package com.hspedu.homework01;

import java.util.Scanner;

public class Homework02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name = scanner.next();
        System.out.println("请输入密码");
        String pwd = scanner.next();
        System.out.println("请输入邮箱");
        String email = scanner.next();
        try {
            userRegister(name,pwd,email);
            System.out.println("注册成功");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

    public static void userRegister(String name, String pwd, String email){
        if(!(name.length() == 2 ||name.length() == 3||name.length() ==4)){
            throw new RuntimeException("用户名长度为2，3或4");
        }

        try {
            int a = Integer.parseInt(pwd);
        } catch (NumberFormatException e) {
            throw new RuntimeException("密码长度为6，要求全是数字");
        }

        if(!(pwd.length() == 6)){
            throw new RuntimeException("密码长度为6，要求全是数字");
        }

        StringBuffer sb = new StringBuffer(email);
        if(!(email.contains("@") && email.contains(".") && sb.indexOf("@") < sb.indexOf("."))){
            throw new RuntimeException("邮箱中包含@和.并且@在。的前面");
        }

    }

}
